package com.gemme.gemme.wode;

import android.os.Bundle;
import android.text.TextUtils;
import android.view.View;
import android.widget.EditText;

import com.gemme.gemme.BaseActivity;
import com.gemme.gemme.R;
import com.gemme.gemme.manager.DataManager;
import com.gemme.gemme.view.Topview;
import com.jaeger.library.StatusBarUtil;

import java.util.HashMap;

//侧滑删除地址
public class NIchengActivity extends BaseActivity{

    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_nicheng);
        initTop();
        initView();
        initIntentData();
    }

    private void initIntentData() {
        try {
            String data = getIntent().getStringExtra("data");
            editV.setText(data + "");
        }catch (Exception e){

        }
    }

    EditText editV;
    View close;

    private void initView() {

        editV = findViewById(R.id.editV);

        close = findViewById(R.id.close);


        close.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View view) {
                editV.setText("");
            }
        });


    }





    private void initTop() {
//        StatusBarUtil.setColor(this,getResources().getColor(R.color.white_color) );
        StatusBarUtil.setTransparent(this);
//        StatusBarUtil.setTranslucent(this,250);
        Topview topview = findViewById(R.id.topview);
        topview.setContentText("编辑昵称");
        topview.setRightText("保存");
        topview.getRightText().setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View view) {
                toServer();
            }
        });
    }

    private void toServer() {
        String name_str = editV.getText() + "";
        if(TextUtils.isEmpty(name_str))
            return;
      /*  Uri.Builder builder = Uri.parse(DataManager.BaseUrl + ":9999/user/userapp/edituser?").buildUpon();
        builder.appendQueryParameter("nickname", name_str);*/

        String url = DataManager.BaseUrl + "user/userapp/edituser?"
                + "nickname="+ name_str;
        HashMap<String, String> headMap = new HashMap<>();
        headMap.put(DataManager.AuthorizationKey,DataManager.getToken(mContext));
//        headMap.put(DataManager.AuthorizationKey,"Bearer 2af9350c-dad4-4e04-b5b9-6a931f9b7b0c");
        DataManager.toServer3(mContext, url, DataManager.POST_TYPE, "", headMap, new DataManager.GeResponse() {
            @Override
            public void onResponse(String response) {
                try{
                    System.out.println();
                    finish();

                }catch (Exception e){

                }
            }
        });
    }


}